import os, geopandas as gpd
departArg=gpd.read_file(os.path.join("dataPais","ARG_adm","ARG_adm1.shp"))
#primero hallamos que tipo de documento es, nos dirá que es un geopandas
type(departArg)
geopandas.geodataframe.GeoDataFrame
#nos va a permitir saber las columnas y las filas
departArg.shape
(24, 10)
#hallaremos el nombre de la columna
departArg.columns
Index(['ID_0', 'ISO', 'NAME_0', 'ID_1', 'NAME_1', 'TYPE_1', 'ENGTYPE_1',
'NL_NAME_1', 'VARNAME_1', 'geometry'],
dtype='object')
#para visualizar cuales son los primeros datos
departArg.head()
| ID_0 | ISO | NAME_0 | ID_1 | NAME_1 | TYPE_1 | ENGTYPE_1 | NL_NAME_1 | VARNAME_1 | geometry | |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 12 | ARG | Argentina | 1 | Buenos Aires | Provincia | Province | None | Baires|Buenos Ayres | MULTIPOLYGON (((-62.79792 -41.02708, -62.79863... |
| 1 | 12 | ARG | Argentina | 2 | Córdoba | Provincia | Province | None | Cordova | POLYGON ((-63.91583 -29.61752, -63.89259 -29.6... |
| 2 | 12 | ARG | Argentina | 3 | Catamarca | Provincia | Province | None | None | POLYGON ((-67.56227 -25.26014, -67.55945 -25.2... |
| 3 | 12 | ARG | Argentina | 4 | Chaco | Provincia | Province | None | El Chaco|Presidente Juan Peron | POLYGON ((-62.32162 -24.10896, -62.32147 -24.1... |
| 4 | 12 | ARG | Argentina | 5 | Chubut | Provincia | Province | None | None | MULTIPOLYGON (((-66.99986 -46.00014, -67.00014... |
#debemos verificar que no tenga ningún valor perdido
departArg[departArg.isna().any(axis=1)]
| ID_0 | ISO | NAME_0 | ID_1 | NAME_1 | TYPE_1 | ENGTYPE_1 | NL_NAME_1 | VARNAME_1 | geometry | |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 12 | ARG | Argentina | 1 | Buenos Aires | Provincia | Province | None | Baires|Buenos Ayres | MULTIPOLYGON (((-62.79792 -41.02708, -62.79863... |
| 1 | 12 | ARG | Argentina | 2 | Córdoba | Provincia | Province | None | Cordova | POLYGON ((-63.91583 -29.61752, -63.89259 -29.6... |
| 2 | 12 | ARG | Argentina | 3 | Catamarca | Provincia | Province | None | None | POLYGON ((-67.56227 -25.26014, -67.55945 -25.2... |
| 3 | 12 | ARG | Argentina | 4 | Chaco | Provincia | Province | None | El Chaco|Presidente Juan Peron | POLYGON ((-62.32162 -24.10896, -62.32147 -24.1... |
| 4 | 12 | ARG | Argentina | 5 | Chubut | Provincia | Province | None | None | MULTIPOLYGON (((-66.99986 -46.00014, -67.00014... |
| 5 | 12 | ARG | Argentina | 6 | Ciudad de Buenos Aires | Distrito Federal | Federal District | None | BUENOS AIRES D.F.|Capital Federal|Distretto Fe... | POLYGON ((-58.44724 -34.69322, -58.46166 -34.7... |
| 6 | 12 | ARG | Argentina | 7 | Corrientes | Provincia | Province | None | None | POLYGON ((-58.15142 -27.26892, -58.13648 -27.2... |
| 7 | 12 | ARG | Argentina | 8 | Entre Ríos | Provincia | Province | None | Entre-Rios | MULTIPOLYGON (((-58.40125 -33.97681, -58.40125... |
| 8 | 12 | ARG | Argentina | 9 | Formosa | Provincia | Province | None | None | POLYGON ((-62.28558 -22.51684, -62.28345 -22.5... |
| 9 | 12 | ARG | Argentina | 10 | Jujuy | Provincia | Province | None | None | POLYGON ((-66.22112 -21.77855, -66.15830 -21.8... |
| 10 | 12 | ARG | Argentina | 11 | La Pampa | Provincia | Province | None | El Pampa|Eva Perón | POLYGON ((-64.39301 -34.99815, -64.35408 -34.9... |
| 11 | 12 | ARG | Argentina | 12 | La Rioja | Provincia | Province | None | None | POLYGON ((-68.49928 -27.75599, -68.50748 -27.7... |
| 12 | 12 | ARG | Argentina | 13 | Mendoza | Provincia | Province | None | None | POLYGON ((-69.11756 -32.01378, -69.11699 -32.0... |
| 13 | 12 | ARG | Argentina | 14 | Misiones | Provincia | Province | None | Missões | POLYGON ((-54.11761 -25.54422, -54.12143 -25.5... |
| 14 | 12 | ARG | Argentina | 15 | Neuquén | Provincia | Province | None | Neuquén | POLYGON ((-70.39233 -36.17107, -70.39227 -36.1... |
| 15 | 12 | ARG | Argentina | 16 | Río Negro | Provincia | Province | None | None | MULTIPOLYGON (((-64.99986 -42.00014, -65.00014... |
| 16 | 12 | ARG | Argentina | 17 | Salta | Provincia | Province | None | None | POLYGON ((-63.78167 -22.00259, -63.76935 -22.0... |
| 17 | 12 | ARG | Argentina | 18 | San Juan | Provincia | Province | None | None | POLYGON ((-69.60582 -28.37947, -69.60296 -28.3... |
| 18 | 12 | ARG | Argentina | 19 | San Luis | Provincia | Province | None | None | POLYGON ((-67.24355 -31.88650, -67.23670 -31.8... |
| 19 | 12 | ARG | Argentina | 20 | Santa Cruz | Provincia | Province | None | None | MULTIPOLYGON (((-69.10917 -51.65569, -69.10917... |
| 20 | 12 | ARG | Argentina | 21 | Santa Fe | Provincia | Province | None | Santa Fé | POLYGON ((-61.71717 -27.99393, -61.66463 -27.9... |
| 21 | 12 | ARG | Argentina | 22 | Santiago del Estero | Provincia | Province | None | None | POLYGON ((-62.87748 -25.65497, -62.86933 -25.6... |
| 22 | 12 | ARG | Argentina | 23 | Tierra del Fuego | Territorio Nacional|Provincia | National Territory | None | Feuerland|Terra del Fuoco|Terre de Feu|Terra d... | MULTIPOLYGON (((-66.54916 -55.05958, -66.54916... |
| 23 | 12 | ARG | Argentina | 24 | Tucumán | Provincia | Province | None | Tucumão | POLYGON ((-65.33595 -26.07400, -65.32600 -26.0... |
#averiguamos que tipo es
departArg.info()
<class 'geopandas.geodataframe.GeoDataFrame'> RangeIndex: 24 entries, 0 to 23 Data columns (total 10 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 ID_0 24 non-null int64 1 ISO 24 non-null object 2 NAME_0 24 non-null object 3 ID_1 24 non-null int64 4 NAME_1 24 non-null object 5 TYPE_1 24 non-null object 6 ENGTYPE_1 24 non-null object 7 NL_NAME_1 0 non-null object 8 VARNAME_1 11 non-null object 9 geometry 24 non-null geometry dtypes: geometry(1), int64(2), object(7) memory usage: 2.0+ KB
# plot simple
departArg.plot()
<AxesSubplot:>
#abrimos los dos mapas siguientes (las provincias y los ríos pertenecientes a Argentina)
riosArg=gpd.read_file(os.path.join("dataPais","ARG_wat","ARG_water_lines_dcw.shp"))
ciudadesArg=gpd.read_file(os.path.join("dataPais","ARG_adm","ARG_adm2.shp"))
#corroboramos que los datos pertenezcan a las ciudades de Argentina
ciudadesArg.head()
| ID_0 | ISO | NAME_0 | ID_1 | NAME_1 | ID_2 | NAME_2 | TYPE_2 | ENGTYPE_2 | NL_NAME_2 | VARNAME_2 | geometry | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 12 | ARG | Argentina | 1 | Buenos Aires | 1 | Adolfo Alsina | Partido | Part | None | Carhue | POLYGON ((-63.39251 -37.72096, -63.39250 -37.7... |
| 1 | 12 | ARG | Argentina | 1 | Buenos Aires | 2 | Adolfo Gonzales Chaves | Partido | Part | None | Adolfo Gonzal | POLYGON ((-60.68344 -38.09533, -60.76242 -38.0... |
| 2 | 12 | ARG | Argentina | 1 | Buenos Aires | 3 | Alberti | Partido | Part | None | None | POLYGON ((-60.32552 -35.23001, -60.32092 -35.2... |
| 3 | 12 | ARG | Argentina | 1 | Buenos Aires | 4 | Almirante Brown | Partido | Part | None | None | POLYGON ((-58.34326 -34.89314, -58.34735 -34.8... |
| 4 | 12 | ARG | Argentina | 1 | Buenos Aires | 5 | Ameghino | Partido | Part | None | None | POLYGON ((-62.08816 -34.97584, -62.18175 -35.0... |
#primero visualizaremos las ciudades
ciudadesArg.plot()
<AxesSubplot:>
#corroboramos que los datos pertenezcan a los ríos de Argentina
riosArg.head()
| F_CODE_DES | HYC_DESCRI | NAM | ISO | NAME_0 | geometry | |
|---|---|---|---|---|---|---|
| 0 | River/Stream | Non-Perennial/Intermittent/Fluctuating | UNK | ARG | Argentina | LINESTRING (-62.95552 -22.01840, -62.95388 -22... |
| 1 | River/Stream | Non-Perennial/Intermittent/Fluctuating | UNK | ARG | Argentina | LINESTRING (-62.95552 -22.01840, -62.96658 -22... |
| 2 | River/Stream | Non-Perennial/Intermittent/Fluctuating | RIO MUERTO | ARG | Argentina | LINESTRING (-62.95552 -22.01840, -62.94953 -22... |
| 3 | River/Stream | Perennial/Permanent | RIO CINCEL | ARG | Argentina | LINESTRING (-65.99427 -22.44915, -65.99702 -22... |
| 4 | River/Stream | Non-Perennial/Intermittent/Fluctuating | UNK | ARG | Argentina | LINESTRING (-63.33389 -22.50236, -63.35136 -22... |
#visualizamos los ríos
riosArg.plot()
<AxesSubplot:>
#le cambiamos las características visuales para que se aprecie mejor la provincia,las ciudades y los ríos
departArg.plot(facecolor="lightskyblue",
edgecolor='darkslategrey',
linewidth=0.1)
<AxesSubplot:>
riosArg.plot(edgecolor='navy',
linewidth=0.4,
linestyle='dashed')
<AxesSubplot:>
ciudadesArg.plot(marker='3',
color='skyblue',
markersize=1,
alpha=1)
<AxesSubplot:>
#ahora uniremos los 3 mapas en uno solo para ello debemos verificar que todos tengan el mismo nombre
departArg.crs
<Geographic 2D CRS: EPSG:4326> Name: WGS 84 Axis Info [ellipsoidal]: - Lat[north]: Geodetic latitude (degree) - Lon[east]: Geodetic longitude (degree) Area of Use: - name: World - bounds: (-180.0, -90.0, 180.0, 90.0) Datum: World Geodetic System 1984 - Ellipsoid: WGS 84 - Prime Meridian: Greenwich
ciudadesArg.crs
<Geographic 2D CRS: EPSG:4326> Name: WGS 84 Axis Info [ellipsoidal]: - Lat[north]: Geodetic latitude (degree) - Lon[east]: Geodetic longitude (degree) Area of Use: - name: World - bounds: (-180.0, -90.0, 180.0, 90.0) Datum: World Geodetic System 1984 - Ellipsoid: WGS 84 - Prime Meridian: Greenwich
riosArg.crs
<Geographic 2D CRS: EPSG:4326> Name: WGS 84 Axis Info [ellipsoidal]: - Lat[north]: Geodetic latitude (degree) - Lon[east]: Geodetic longitude (degree) Area of Use: - name: World - bounds: (-180.0, -90.0, 180.0, 90.0) Datum: World Geodetic System 1984 - Ellipsoid: WGS 84 - Prime Meridian: Greenwich
#ahora debemos poner capa por capa
base = departArg.plot(facecolor="lightskyblue", edgecolor='darkslategrey', linewidth=1,figsize=(12,12))
ciudadesArg.plot(marker='6', color='honeydew', markersize=5,alpha=0.9,
ax=base)
riosArg.plot(edgecolor='navy', linewidth=0.2,
ax=base)
<AxesSubplot:>
import folium
#para realizarlo de forma dinamica
m=ciudadesArg.explore(color="honeydew",
name="ciudadesArg")
m=riosArg.explore(m=m, color="navy",
name="riosArg")
#folium.LayerControl().add_to(m)
m